import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import tailwindcss from 'tailwindcss'
import autoprefixer from 'autoprefixer'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    tailwindcss,
    autoprefixer
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
 // vue3 解决使用datav在页面中无法使用问题 --start
 build: {
  commonjsOptions: {
    include: [/node_modules/],
  },
},
optimizeDeps: {
  //开发时，解决这些commonjs包转化为esm包
  include: [
    "@jiaminghi/c-render",
    "@jiaminghi/c-render/lib/plugin/util",
    "@jiaminghi/charts/lib/util/index",
    "@jiaminghi/charts/lib/util",
    "@jiaminghi/charts/lib/extend/index",
    "@jiaminghi/charts",
    "@jiaminghi/color",
  ],
},
  server: {
    proxy: {
      '/api': {
        target: 'http://koa.ziyoujike.cn', // 将请求代理到的目标地址
        // target: 'http://localhost:8080', // 将请求代理到的目标地址
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '') // 将请求路径重写，去掉开头的 '/api'
      }
    }
  },
})
